<script lang="ts" setup>
import { useMessage } from 'naive-ui';
import { ref } from 'vue';
import type { Fn } from '@vueuse/core';
import * as service from '@/views/im/user/modules/api';
import { isSuccess } from '@/utils/response';

const props = defineProps<{
  id: Fn;
  callback: Fn;
}>();

const message = useMessage();
const showModal = ref(false);

async function open() {
  showModal.value = true;
}

async function remove() {
  const response = await service.remove({ id: props.id() });
  if (isSuccess(response)) {
    message.info('删除成功');
    showModal.value = false;
    if (props.callback) {
      props.callback();
    }
  }
}
</script>

<template>
  <NButton type="error" @click="open()">删除</NButton>
  <n-modal
    v-model:show="showModal"
    title="确认要删除吗?"
    preset="dialog"
    positive-text="确认"
    negative-text="取消"
    @positive-click="remove()"
  ></n-modal>
</template>

<style scoped>
.card {
  width: 350px;
}
</style>
@/service/api/chat-user
